<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/3/21
  Time: 13:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>商品列表</title>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.css">
    <script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap.js"></script>
</head>
<body>
        <div style="float:right;font-size: 16px">
            欢迎<span style="color:red;font-size: 20px">${sessionScope.user.realname}</span>登录系统！
            <button type="button" class="btn btn-default" onclick="location.href='/user/logout.do'">退出</button>
        </div>

<form class="form-inline" role="form" method="post" action="/product/list.do">
        <div class="form-group">
            <label class="sr-only" for="pname">商品名称</label>
            <input type="text" class="form-control" id="pname" placeholder="请输入商品名称" name="pname" value="${pname}">

        </div>
        <button type="submit" class="btn btn-default">搜索</button>
    </form>
    <table class="table table-striped">
        <caption style="font-size: 30px;font-weight: 900">商品列表</caption>
        <thead>
            <tr>
                <th>商品ID</th>
                <th>商品名称</th>
                <th>商品价格</th>
                <th>商品数量</th>
                <th>商品描述</th>
                <th>所属类别</th>
                <th>所属用户</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${products.list}" var="product">
            <tr>
                <td>${product.pid}</td>
                <td>${product.pname}</td>
                <td>${product.price}</td>
                <td>${product.num}</td>
                <td>${product.desc}</td>
                <td>${product.type.tname}</td>
                <td>${product.user.username}</td>
                <td><a href="/product/preUpdate.do?pid=${product.pid}">修改</a>|
                    <a href="/product/delete.do?pid=${product.pid}">删除</a></td>
            </tr>
            </c:forEach>

    </table>
    <div align="center">
        <ul class="pagination">
            <c:if test="${products.hasPreviousPage}">
                <li><a href="/product/list.do?pageNum=${products.pageNum-1}">&laquo;</a></li>
            </c:if>
            <c:if test="${!products.hasPreviousPage}">
                <li><a href="#">&laquo;</a></li>
            </c:if>

            <c:forEach begin="1" end="${products.pages}" var="p">
                <c:if test="${products.pageNum==p}">
                    <li class="active"><a href="/product/list.do?pageNum=${p}">${p}</a></li>
                </c:if>
                <c:if test="${products.pageNum!=p}">
                    <li><a href="/product/list.do?pageNum=${p}">${p}</a></li>
                </c:if>
            </c:forEach>
            <c:if test="${products.hasNextPage}">
                <li><a href="/product/list.do?pageNum=${products.pageNum+1}">&raquo;</a></li>
            </c:if>
            <c:if test="${!products.hasNextPage}">
                <li><a href="#">&raquo;</a></li>
            </c:if>
        </ul>
    </div>

</body>
</html>
